<template>
  <div class="sosuo">
    <div class="search-main">
      <div class="search-left">
        <span>
          <van-icon name="search" @click="doserch()" />
        </span>
        <input v-model="text" type="text" placeholder="请输入关键字" style="outline: none;" />
      </div>
      <div class="search-right">
        <span @click="goOff()">取消</span>
      </div>
    </div>
    <div class="search-counter">
      <div class="counter-title">
        <h2>热门搜索</h2>
      </div>
      <ul class="counter-main">
        <li v-for="(item,name) in show" :key="name" @click="dohot(name)">{{item}}</li>
      </ul>
    </div>
    <bookshow v-for="(item,name) in showbook" :key="name" :item="item" />
  </div>
</template>

<script>
// import { Toast } from "vant";
import bookshow from "@/components/bookshow.vue";
import foot from "@/components/foot.vue";
export default {
  data() {
    return {
      value: "",
      show: ["汉乡", "绝品邪少", "最强兵王"],
      text: "",
      showbook: [],
    };
  },
  components: {
    bookshow,
    foot,
  },
  methods: {
    goOff() {
      this.$router.go(-1);
    },
    dohot(name){
      this.text = this.show[name]
    },
    doserch() {
      
      if(this.text == '%' || this.text==''){
        console.log(this.text)
     } else{
       var search = this.text;
     }
      this.$axios.post("/api/Search", { search: search }).then((data) => {
        console.log(data);
        if (data.data.code == 200) {
          alert(data.data.msg);
        }
        console.log(data.data.data);
        this.showbook = data.data.data;
        console.log(this.showbook);
      });
    },
  },
};
</script>

<style scoped>
.sosuo {
  text-align: center;
}
.search-main {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  box-sizing: border-box;
  width: 100%;
  height: 1.2rem;
  padding: 0.23rem 0.15rem 0.23rem;
  z-index: 205;
  background-color: #f5f5f5;
  display: flex;
}
.search-left {
  box-sizing: border-box;
  height: 0.8rem;
  border-radius: 0.4rem;
  flex: 0.8;
  position: relative;
  background-color: #fff;
  border-radius: 1rem;
  margin-right: 0.2rem;
}
.search-left span {
  position: absolute;
  left: 0;
  top: 0;
  /* background: url(../assets/ss.png) no-repeat center center; */
  /* background-size: .8rem auto; */
  font-size: 0.5rem;
  background-position: 50% 50%;
  height: 0.8rem;
  width: 0.8rem;
}
.van-icon {
  margin-top: 0.11rem;
  margin-left: 0.2rem;
}
.search-left input {
  position: absolute;
  left: 0.798872rem;
  top: 0.046992rem;
  font-size: 0.35rem;
  height: 0.68rem;
  padding-left: 0.8em;
  padding-right: 0.9rem;
  border: none;
}
.search-right {
  box-sizing: border-box;
  flex: 0.17;
  border: 1px solid #d7d7d7;
  border-radius: 0.1rem;
}
.search-right span {
  font-size: 0.328947rem;
  line-height: 0.8rem;
}
.search-counter {
  margin-top: 1.198308rem;
}
.counter-title {
  width: 94%;
  display: inline-block;
}
.counter-title h2 {
  text-align: left;
  font-size: 0.35rem;
  line-height: 0.35rem;
  color: #8e8e8e;
  font-weight: 400;
  padding: 0.6rem 0 0.35rem 0.2rem;
}
.counter-main {
  width: 94%;
  display: inline-block;
  text-align: left;
}
.counter-main li {
  display: inline-block;
  color: #000;
  background-color: #fffafaa1;
  border: 1px solid #c2c1c1;
  font-size: 0.3rem;
  font-weight: 700;
  height: 30px;
  line-height: 30px;
  border-radius: 0.3rem;
  padding: 0 0.4rem;
  margin: 0 0.2rem 0.3rem 0;
}
</style>
